/*
* Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: ViewManager.js.
*/

// holds the currently displayed view
var currentView;
// holds the current view history
var viewHistory = new Array();

function showView(view) {
    if (view.visible) {

        var isPreviousView = false;

        for (var i = 0; i < viewHistory.length; i++) {
            if (view == viewHistory.indexOf(i)) {
                alreadyUsed = true;
                viewHistory.splice(i);
                break;
            }
        }

        if (currentView != view) {
            if(currentView && !isPreviousView) {
                viewHistory.push(currentView);
            }

        currentView = view;
        }
    }
}

function connectViewEvents(view) {
    view.visibleChanged.connect(function() {
        SVM.showView(view);
    });
}
